package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.Issue;
import com.cskaoyan.bean.basebean.BaseRespVo;
import com.cskaoyan.bean.zhao_order_bean.BasePageData;
import com.cskaoyan.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <h3>market</h3>
 *
 * @author:Zhao
 * @date:2021-10-20 16:04:45
 * @description:
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {
    @Autowired
    IssueService issueService;

    @RequestMapping("list")
    public BaseRespVo list(String question, BaseParam baseParam) {
        BasePageData data = issueService.query(question, baseParam);

        return BaseRespVo.ok(data);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Map map) {
        String answer = (String) map.get("answer");
        String question = (String) map.get("question");

        Issue issue = issueService.create(answer, question);

        return BaseRespVo.ok(issue);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Map map) {
        String answer = (String) map.get("answer");
        String question = (String) map.get("question");
        Integer id = (Integer) map.get("id");

        Issue issue = issueService.update(id, answer, question);

        return BaseRespVo.ok(issue);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer id = (Integer) map.get("id");

        issueService.delete(id);

        return BaseRespVo.ok();
    }

}
